Write-Output "Updating UploadVideoEnabled"

$UploadVideoEnabledKey = "UploadVideoEnabled";
$MediaEncoderPathKey = "MediaEncoderPath";

$os = Get-WMIObject win32_operatingsystem
[bool] $encoderFound = $False;
[string] $encoderInstallDir = [string].Empty;

# Seach in 32bits software folder
$encoderFound = Test-Path 'HKLM:SOFTWARE\Microsoft\Expression\Encoder\3.0\';    
if($encoderFound) 
{
   $entryProperty = Get-ItemProperty -path HKLM:\SOFTWARE\Microsoft\Expression\Encoder\3.0\
   $encoderInstallDir = $entryProperty.InstallPath
}

#Search in 64 bit keys folders
if ($os.OSArchitecture -eq "64-bit") {
    #Wow folder, 64 bits
    $encoderFound = Test-Path 'HKLM:SOFTWARE\Wow6432Node\Microsoft\Expression\Encoder\3.0\';    
    if($encoderFound)
    {
		$entryProperty = Get-ItemProperty -path HKLM:\SOFTWARE\Wow6432Node\Microsoft\Expression\Encoder\3.0\
		$encoderInstallDir = $entryProperty.InstallPath
	}
}

if ($encoderFound)
{
	Write-Output "Expression Encoder 3.0 installed setting UploadVideoEnable = true"
	Write-Output $encoderInstallDir
}
else
{
	Write-Output "Expression Encoder 3.0 not found setting UploadVideoEnable = false"
}

$location = [Environment]::CurrentDirectory=(Get-Location -PSProvider FileSystem).ProviderPath
[xml]$doc = get-content (Join-Path $location "..\..\..\code\Web\Web.config")

$node = $doc.configuration.SelectSingleNode("appSettings/add[@key='$UploadVideoEnabledKey']")
$node.value = $encoderFound.ToString()
$node = $doc.configuration.SelectSingleNode("appSettings/add[@key='$MediaEncoderPathKey']")
$node.value = $encoderInstallDir
        
$doc.save((Join-Path $location "..\..\..\code\Web\Web.config"))

Write-Output "Setting UploadVideoEnable and Encode path completed!"

